<?php
/**
 * 目录管理
 * @since   2018-01-16
 * @author  zhaoxiang <zhaoxiang051405@gmail.com>
 */

namespace app\backstage\controller;


use app\model\AbnormalConfig as AbnormalModel;
use app\model\AbnormalNotice;
use app\util\ReturnCode;
use app\util\Tools;
use think\Db;

class Platform extends Base {

    /**
     * 获取列表
     */
    public function index() {
        $list = Db::name('platform')->order('id', 'DESC')->select();
        return $this->buildSuccess([
            'list' => $list
        ], '操作成功');
    }

    /**
     * 新增
     */
    public function add() {
        $postData = $this->request->post();
        if (empty($postData['name'])) {
            return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '平台名称必须填写');
        }
        if (empty($postData['abbr'])) {
            return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '平台简称必须填写');
        }
        $res = \app\model\Platform::create($postData);
        if ($res === false) {
            return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
        } else {
            return $this->buildSuccess([]);
        }
    }



    /**
     * 编辑
     */
    public function edit() {
        $postData = $this->request->post();
        if (empty($postData['name'])) {
            return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '平台名称必须填写');
        }
        $res = \app\model\Platform::update($postData);
        if ($res === false) {
            return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
        } else {
            return $this->buildSuccess([]);
        }
    }



}
